<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>校园一卡通</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="o n">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/store/bound/css/style.css">
    <link rel="stylesheet" href="/assets/store/bound/css/layer.css">
</head>
<body>
    <div class="wraper">
        <div class="header">
            <a href="javascript:history.go(-1)" class="iconfont icon-zuo back"></a>
            <div class="title text-center font-16">绑定校园卡</div>
        </div>
        <div class="classify content margin-t12">
            <div class="content-list flex">
                <div class="user-hint">卡户账号</div>
                <div class="input"> 
                    <input type="text" id="number2" placeholder="卡户账号">
                </div>
            </div>
            <div class="content-list flex">
                <div class="user-hint">学工号</div>
                <div class="input">
                    <input type="text" id="number" placeholder="学工号">
                </div>
            </div>
            <div class="content-list flex">
                <div class="user-hint">解绑密码</div>
                <div class="input" >
                    <input type="password" id="password" placeholder="解绑密码">
                </div>
            </div>
            <p><a href="#" class="btn text-center font-16" id="bind">绑定</a></p>
            <input type="hidden" id="redirect_url" value="{BEESCRM:$redirect_url}" />
            <input type="hidden" id="account_id" value="{BEESCRM:$account_id}" />
        </div>
    </div>
</body>
<script src="/assets/store/bound/js/jquery-2.1.0.min.js"></script>
<script src="/assets/store/bound/js/layer.js"></script>
<script src="/assets/store/bound/js/public.js"></script> 
<script>
    $('#bind').on('click',function(){
        var number2 = $('#number2').val();
        var number = $('#number').val();
        var password = $('#password').val();
        var account_id = $('#account_id').val();
        var redirect_url = $('#redirect_url').val();
        if(number2.length <= 0){
            fm.alert('卡户账号不能为空');
            return false;
        }
        if(/[^\w\.\/]/ig.test(number2)){
            fm.alert('卡户账号只能是字母和数字');
            return false;
        }
        if(number.length <= 0){
            fm.alert('学工号不能为空');
            return false;
        }
        if(/[^\w\.\/]/ig.test(number)){
            fm.alert('学工号只能是字母和数字');
            return false;
        }
        if(password.length <= 0){
            fm.alert('解绑密码不能为空');
            return false;
        }
        $.ajax({
            url: "/base/CampusCard/doBind/account_id/"+account_id,
            type: 'post',
            dataType: 'json',
            data: {number2:number2,number:number,password:password,redirect_url:redirect_url},
            success: function (res) {
                if (res.status == 'S') {
                    fm.alert(res.message, "", 2, "");
                    window.sessionStorage.setItem("local_url",res.url);
                    setTimeout(redirect, 2000);
                } else if(res.status == 'BF'){
                    fm.alert(res.message,"",30,"");
                    return false;
                } else {
                    fm.alert(res.message);
                    return false;
                }
            }
        });
    });
    function redirect() {
        window.location.href = window.sessionStorage.getItem("local_url");
        window.sessionStorage.setItem("local_url",null);
    }
</script>
